package com.hhf.rpa.engine.service.impl;

import com.hhf.rpa.engine.model.ScriptExecConfigurer;
import com.hhf.rpa.engine.service.ScriptExecutor;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
@Service
public class MutilThreadScriptExecutor implements ScriptExecutor {

    public Object execScript(ScriptExecConfigurer configurer) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        System.setProperty("java.awt.headless", "false");
        Class<?> clazz = Class.forName(configurer.getClassName());
        Object scriptInstance = clazz.getDeclaredConstructor().newInstance();
        if (scriptInstance instanceof Runnable) {
            ((Runnable) scriptInstance).run();
        } else {
            throw new IllegalArgumentException("The specified class must implement the Runnable interface.");
        }
        return null;
    }

}
